/*
 * drv_uart.h
 *
 *  Created on: Jul 12, 2021
 *      Author: dbw
 */

#ifndef DRV_UART_H_
#define DRV_UART_H_

#include "common.h"
#include "stm32f4xx.h"

#define UART_RX_BUFSIZE	 128

typedef struct uart uart_t;

typedef void (*uart_rx_cb_t)(uart_t *uart, uint8_t *buf, uint32_t len);

struct uart
{
    UART_HandleTypeDef *handle;

    uint8_t rx_buf[UART_RX_BUFSIZE];
    uint32_t rx_index;
    uart_rx_cb_t rx_cb;
};

extern uart_t uart1;

void drv_uart_init(void);
void drv_uart_set_callback(uart_t *uart, uart_rx_cb_t rx_cb);
void drv_uart_send_byte(uart_t *uart, uint8_t data);
void drv_uart_send(uart_t *uart, const void *buf, int len);
void drv_uart_send_str(uart_t *uart, const char *str);

#endif /* DRV_UART_H_ */
